#include<iostream>
#include<string>
#include<vector>
using namespace std;

string trans(string s, int n) {
	vector<string> words;
	string word;
	bool isSpace = isspace(s[0]);
	//大小写转换
	for (auto& str : s) {
		if (str >= 'a' && str <= 'z') str -= 32;
		else if (str >= 'A' && str <= 'Z') str += 32;

		if (isspace(str)) {
			if (!word.empty() && !isSpace) {
				words.push_back(word);
				word.clear();
			}
			word += str;
			isSpace = true;
		}

		else {
			if (!word.empty() && isSpace) {
				words.push_back(word);
				word.clear();
			}
			word += str;
			isSpace = false;
		}
	}
	if (!word.empty()) words.push_back(word);
	string res;
	for (int i = words.size() - 1; i >= 0; i--) {
		res += words[i];
	}
	return res;
}
int main()
{
	string str = "This is a sample";
	trans(str, 16);
	return 0;
}